home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / BUTTON.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  3.7 KB  |  149 lines

  1. { button.pas -- Buttons in dialogs }
  2.  
  3. program Button;
  4.  
  5. {$R button.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects, ButtonU;
  8.  
  9. const
  10.  
  11.   id_Menu   = 100;  { Menu resource ID }
  12.   cm_Dialog = 101;  { Dialog-command ID }
  13.   id_Dialog = 200;  { Dialog resource ID }
  14.  
  15.   id_cb1    = 101;  { Check box IDs }
  16.   id_cb2    = 102;
  17.   id_cb3    = 103;
  18.   id_rb1    = 104;  { First group of radio button IDs }
  19.   id_rb2    = 105;
  20.   id_rb3    = 106;
  21.   id_rb4    = 107;  { Second group of radio button IDs }
  22.   id_rb5    = 108;
  23.   id_rb6    = 109;
  24.  
  25. type
  26.  
  27.   PDialogRec = ^DialogRec;  { Pointer to DialogRec record }
  28.   DialogRec = record
  29.     Checks: CBSet;          { Check box bit set }
  30.     RadiosG1: RadioSet;     { Radio buttons -- Group 1 }
  31.     RadiosG2: RadioSet;     { Radio buttons -- Group 2 }
  32.   end;
  33.  
  34.   PBDialog = ^BDialog;
  35.   BDialog = object(TDialog)
  36.     DataPointer: PDialogRec;
  37.     constructor Init(AParent: PWindowsObject; AName: PChar;
  38.       P: PDialogRec);
  39.     procedure SetupWindow; virtual;
  40.     procedure IDCB1(var Msg: TMessage);
  41.       virtual id_First + id_cb1;
  42.     procedure Ok(var Msg: TMessage);
  43.       virtual id_First + id_Ok;
  44.   end;
  45.  
  46.   DButtonApplication = object(TApplication)
  47.     procedure InitMainWindow; virtual;
  48.   end;
  49.  
  50.   PDButtonWindow = ^DButtonWindow;
  51.   DButtonWindow = object(TWindow)
  52.     DialogData: DialogRec;
  53.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  54.     procedure CMDialog(var Msg: TMessage);
  55.       virtual cm_First + cm_Dialog;
  56.   end;
  57.  
  58.  
  59. { BDialog }
  60.  
  61. {- Construct BDialog instance. P addresses dialog data record. }
  62. constructor BDialog.Init(AParent: PWindowsObject; AName: PChar;
  63.   P: PDialogRec);
  64. begin
  65.   TDialog.Init(AParent, AName);
  66.   DataPointer := P  { Save pointer to caller's dialog record }
  67. end;
  68.  
  69. {- Prepare initial control values }
  70. procedure BDialog.SetupWindow;
  71. var
  72.   I: Integer;
  73. begin
  74.   TDialog.SetUpWindow;
  75.   with DataPointer^ do
  76.   begin
  77.     SetChecks(HWindow, Checks, id_cb1, id_cb3);
  78.     SetRadios(HWindow, RadiosG1, id_rb1, id_rb3);
  79.     SetRadios(HWindow, RadiosG2, id_rb4, id_rb6)
  80.   end
  81. end;
  82.  
  83. {- Demonstrate interactive response to button activity }
  84. procedure BDialog.IDCB1(var Msg: TMessage);
  85. begin
  86.   MessageBeep(0)  { First check box beeps when selected }
  87. end;
  88.  
  89. {- Respond to Ok button }
  90. procedure BDialog.Ok(var Msg: TMessage);
  91. begin
  92.   with DataPointer^ do
  93.   begin
  94.     GetChecks(HWindow, Checks, id_cb1, id_cb3);
  95.     GetChecks(HWindow, RadiosG1, id_rb1, id_rb3);
  96.     GetChecks(HWindow, RadiosG2, id_rb4, id_rb6)
  97.   end;
  98.   TDialog.Ok(Msg)
  99. end;
  100.  
  101.  
  102. { DButtonApplication }
  103.  
  104. {- Initialize DButtonApplication object's window }
  105. procedure DButtonApplication.InitMainWindow;
  106. begin
  107.   MainWindow := New(PDButtonWindow, Init(nil, 'Button'))
  108. end;
  109.  
  110.  
  111. { DButtonWindow }
  112.  
  113. {- Construct DButtonWindow object; Initialize dialog data record }
  114. constructor DButtonWindow.Init(AParent: PWindowsObject;
  115.   ATitle: PChar);
  116. begin
  117.   TWindow.Init(AParent, ATitle);
  118.   Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
  119.   with DialogData do
  120.   begin
  121.     Checks := [0, 2];  { Set 1st and 3rd check boxes }
  122.     RadiosG1 := [1];   { Set 2nd radio button in first group }
  123.     RadiosG2 := [0]    { Set 1st radio button in second group }
  124.   end;
  125. end;
  126.  
  127. {- Execute Menu:Dialog command }
  128. procedure DButtonWindow.CMDialog(var Msg: TMessage);
  129. begin
  130.   Application^.ExecDialog(New(PBDialog,
  131.     Init(@Self, PChar(id_Dialog), @DialogData)))
  132. end;
  133.  
  134. var
  135.  
  136.   DButtonApp: DButtonApplication;
  137.  
  138. begin
  139.   DButtonApp.Init('DButtonApp');
  140.   DButtonApp.Run;
  141.   DButtonApp.Done
  142. end.
  143.  
  144.  
  145. {--------------------------------------------------------------
  146.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  147.   Revision 1.00    Date: 3/19/1991
  148. ---------------------------------------------------------------}
  149.